package com.googlecode.scenemaker3d.services
{
	import flash.events.EventDispatcher;
	
	import org.papervision3d.materials.ColorMaterial;
	import org.papervision3d.materials.utils.MaterialsList;
	import org.papervision3d.objects.DisplayObject3D;
	import org.papervision3d.objects.primitives.Cube;
	import org.papervision3d.objects.primitives.Plane;
	import org.papervision3d.materials.MovieMaterial;
	import org.papervision3d.materials.MovieAssetMaterial;
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import org.papervision3d.materials.BitmapFileMaterial;
	import org.papervision3d.events.InteractiveScene3DEvent;
	import org.papervision3d.materials.special.LineMaterial;
	import org.papervision3d.core.geom.Lines3D;
	import org.papervision3d.core.geom.renderables.Vertex3D;
	import org.papervision3d.core.geom.renderables.Line3D;

	public class PVServices extends EventDispatcher
	{
		/* private const FRONT:ColorMaterial = new ColorMaterial();
		private const BACK:ColorMaterial = new ColorMaterial(0xff0000);
		private const TOP:ColorMaterial = new ColorMaterial(0xfff000);
		private const BOTTOM:ColorMaterial = new ColorMaterial(0xffff00);
		private const LEFT:ColorMaterial = new ColorMaterial(0x0ff000);
		private const RIGHT:ColorMaterial = new ColorMaterial(0xfff00f); */

		private const FRONT:BitmapFileMaterial = new BitmapFileMaterial("com/googlecode/scenemaker3d/services/assets/front.jpg");
		private const BACK:BitmapFileMaterial = new BitmapFileMaterial("com/googlecode/scenemaker3d/services/assets/back.jpg");
		private const TOP:BitmapFileMaterial = new BitmapFileMaterial("com/googlecode/scenemaker3d/services/assets/top.jpg");
		private const BOTTOM:BitmapFileMaterial = new BitmapFileMaterial("com/googlecode/scenemaker3d/services/assets/bottom.jpg");
		private const LEFT:BitmapFileMaterial = new BitmapFileMaterial("com/googlecode/scenemaker3d/services/assets/left.jpg");
		private const RIGHT:BitmapFileMaterial = new BitmapFileMaterial("com/googlecode/scenemaker3d/services/assets/right.jpg");
		
		private const WIDTH:Number = 1000;
		private const HEIGHT:Number = 1000;
		private const DEPTH:Number = 1000;
		
		public function PVServices()
		{
		}
		
		public function getDefaultPlane():Plane{
			var mat:BitmapFileMaterial = new BitmapFileMaterial("com/googlecode/scenemaker3d/services/assets/front.jpg");
			//var mat:ColorMaterial = new ColorMaterial(0x0ff000, .2);
			//mat.interactive = true;
			mat.doubleSided = true;
			//mat.interactive = true;

			var plane:Plane = new Plane(mat,WIDTH,HEIGHT,20, 20);
			
			plane.name = "plane";
			
			//Since planes have no thickness when viewed edge on, they will have lines around edges.
			var lm:LineMaterial = new LineMaterial(0x909090, 1);
			var lines:Lines3D = new Lines3D(lm);
			lines.name = "outline";
			
			var vt1:Vertex3D;
			var vt2:Vertex3D;
			
			var l:Line3D;
			
			//Top and bottom
			vt1 = new Vertex3D(-WIDTH / 2, HEIGHT / 2, 0);
			vt2 = new Vertex3D(WIDTH / 2, HEIGHT / 2, 0);
			
			l = new Line3D(lines, lm, 4, vt1, vt2);
			
			lines.addLine(l);
			
			vt1 = new Vertex3D(-WIDTH / 2, -HEIGHT / 2, 0);
			vt2 = new Vertex3D(WIDTH / 2, -HEIGHT / 2, 0);
			
			l = new Line3D(lines, lm, 4, vt1, vt2);
			
			lines.addLine(l);
			
			//Sides
			vt1 = new Vertex3D(-WIDTH / 2, HEIGHT / 2, 0);
			vt2 = new Vertex3D(-WIDTH / 2, -HEIGHT / 2, 0);
			
			l = new Line3D(lines, lm, 4, vt1, vt2);
			
			lines.addLine(l);
			
			vt1 = new Vertex3D(WIDTH / 2, HEIGHT / 2, 0);
			vt2 = new Vertex3D(WIDTH / 2, -HEIGHT / 2, 0);
			
			l = new Line3D(lines, lm, 4, vt1, vt2);
			
			lines.addLine(l);
			
			plane.addChild(lines);
			
			return plane;
		}
		public function getDefaultCube():Cube{
			var matList:MaterialsList = new MaterialsList();
			//FRONT.interactive = true;
			//BACK.interactive = true;
			//TOP.interactive = true;
			//BOTTOM.interactive = true;
			//LEFT.interactive = true;
			//RIGHT.interactive = true;
			
			matList.addMaterial(FRONT, "front");
			matList.addMaterial(BACK, "back");
			matList.addMaterial(TOP, "top");
			matList.addMaterial(BOTTOM, "bottom");
			matList.addMaterial(LEFT, "left");
			matList.addMaterial(RIGHT, "right");
			
			var cube:Cube = new Cube(matList, WIDTH, DEPTH, HEIGHT);
			cube.name = "cube";
			
			return cube;
		}
	}
}